home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software 2000
/
Software 2000 Volume 1 (Disc 1 of 2).iso
/
education
/
e123.dms
/
e123.adf
/
Prog.asc
< prev
next >
Wrap
Text File
|
1993-04-04
|
15KB
|
419 lines
'Starting to programme? Jump in the deep end and write your own art
'package! This may help a little. Although there are hundreds of AMOS
'commands we only use around 30 here. It is neither efficient nor elegant
'but it should be readable and may help the odd penny to drop.
'
'Absolute beginners should ensure they understand the use of loops. Try
'writing a programme to print the numbers 1 to 10 on the screen. We might
'write - Print 1 : Print 2 : Print 3 : Etc. This would work but we have to
'do all the tricky headwork; working out what the next number is! Better to
'get the computer to do it for you - that's what you paid for! So we set
'up a variable called NUMBER. Think of a variable as a named box in which we
'place a value. We use a loop to INCrement and print the value of NUMBER.
'The instructions inside a loop are carried out over and over again until
'something happens (that we have planned!) that lets us jump out of the loop.
'You are the variable NUMBER! Work through these loops & see how you change!
'
' NUMBER = 0 NUMBER = 1
' Do Do
' Inc NUMBER Try this one -> Print NUMBER
' Print NUMBER What happened? Inc NUMBER
' Exit If NUMBER = 10 Exit If NUMBER = 10
' Loop Loop
'
' Do/Loop structures are crude; we have to tell them what to do and when
' to Exit etc. We could try Repeat/Until and While/Wend loops...
' the symbol < translates as "is less than"
'
' NUMBER = 0 NUMBER = 0
' Repeat Checks value here -> While NUMBER < 10
' Inc NUMBER Inc NUMBER
' Print NUMBER Print NUMBER
' Until NUMBER = 10 <- Checks value here Wend
'
' Did you spot the difference? It still looks like hard work to me!
' The For/Next loop will do all the work for us. How lazy can we get?
'
' For NUMBER = 1 To 10
' Print NUMBER
' Next NUMBER
'
' So use the right loop for the job you are doing and save yourself time,
' effort, memory and disc space! Be as lazy as you can! And now....
'
' ==============================================
' = A Bare Bones Drawing Programme. =
' = by Duncan Moran =
' ==============================================
'
' Use MERGE ASCII (press right mouse button) to load into your AMOS editor
'
' Just tart it up a bit. Add an amusing & colourful cartoon like
' character and a jingly jangly tune and sell the lot for £25!!!!
'
'
'
' Anything written over here with a
' <= <= <= <= <= ' at the start of the line is for you to read.
' The computer only needs the lines starting on the left
' without a ' at the start.
'
'
'
' Set global variables for use throughout the programme
'
' Variable Names What they contain
' -------------- -----------------
' XSTARTPOS & YSTARTPOS = X & Y Start positions
' XPOSNOW & YPOSNOW = their position now
' MZ = Number of the zone on the
' screen at which the mouse
' is pointing = Mouse Zone
' -------------------- --------------------
'
'
Global XSTARTPOS,YSTARTPOS,XPOSNOW,YPOSNOW,MZ
'
' Start here.....
'
SET_IT_UP
'
' The Main Loop
Do
WHICH_BUTTON
Loop
'
'
' That's all there is to it! Pretty lazy eh!
' Worth £25 of anyones money don't you think?
'
'
' These are the procedures that do all the work.
'
Procedure SET_IT_UP
' N.B. Computers start counting from zero.
'
' Open screen number 0
' Pictures on a screen are made up from dots which
' are refered to as Pixels - Picture elements.
' Make our screen 320 pixels wide by 200 high
' give it 2 colours and make it low resolution.
'
' < 320 >
' ___________________ The character in the middle
' - : : is 160 across (X direction)
' Rows go - : : and 100 down (Y direction)
' across - : ¤ : 200
' - : :
' -------------------
' ||||||||
' Columns go up & down
'
' Think how far along the R ow and then how far down the C olumn
' Think R hubarb and C ustard! Hope this is not too technical!
'
'
' Nurse! The......
'
Screen Open 0,320,200,2,Lowres
'
'
' Screen 1 will be the one we draw on
' Screen 0 will be out of sight and used to
' hold a copy of our drawing ready to be undone.
'
Screen Open 1,320,200,2,Lowres
'
' Set colour 0 to white and colour 1 to black
' Colours are made from R ed, G reen and B lue parts.
' We tell the computer about colours like this -> $RGB.
' Each colour can have a value from 0 to 15 denoted by
' 0 1 2 3 4 5 6 7 8 9 A B C D E F
' $FFF represents maximum red, blue and green = white.
' $000 represents NO red, blue or green which = black.
' AMOS will not show leading 0's so this will be $0
Palette $FFF,$000
'
' Open a narrow (32 rows) toolbox screen
Screen Open 2,320,32,2,Lowres
'
' set toolbox colours to $FF0 and $00F
' $FF0 = maximum Red and Green No Blue = yellow
' $00F = NO Red or Green = just Blue.
'
' Compare with your photographic negatives.
'
Palette $FF0,$F
'
' Call the procedure to make the buttons.
SET_UP_BUTTONS
'
End Proc
'
Procedure SET_UP_BUTTONS
'
' Set the Ink colour to colour 1 (blue)
' and the Paper colour to colour 0 (yellow)
Ink 1,0
' The variables UPPERLEFT, BOTTOMRIGHT & COUNTER are Local
' Variables they have no value outside this procedure not
' like the Global variables which hold a value throughout.
' Top Left corner starts at position 1 (measured in Pixels)
UPPERLEFT=1
' Bottom Right is at 53
BOTTOMRIGHT=53
' Make space to remember where the six buttons are
Reserve Zone 6
'
' For/Next loop. Loops for specified number of times.
' Loop 6 times. Each loop draws a box on the screen
' and sets the zone to the same size. The value of COUNTER
' starts as 1. It increases on each loop until it
' reaches 7 which is too high & so we drop out of the loop.
'
For COUNTER=1 To 6
'
' Draw a box/button from Top Left to Bottom Right
' The top line of button is always 5 rows down and the
' bottom line will be on the 25th row. Constant values.
Box UPPERLEFT,5 To BOTTOMRIGHT,25
'
' Zone number = current value of COUNTER (1 to 6)
' Set dimensions to the same as those of the box.
Set Zone COUNTER,UPPERLEFT,5 To BOTTOMRIGHT,25
'
' Read the next item from the DATA list below.
' Variable names with a $ on the end will hold a string
' of characters contained within "inverted commas".
' These are known as String Variables.
Read WORD$
'
' Use UPPERLEFT to work out where to stick it
' on the 13th row.
Text UPPERLEFT+2,13,WORD$
'
' Shove both corners along 53 places
' N.B. Use a colon : to seperate instructions on the
' same line
Add UPPERLEFT,53 : Add BOTTOMRIGHT,53
'
' If COUNTER is not finished do next loop
Next COUNTER
'
' Write a couple more words to finish it off
Text 12,22," Exit" : Text 178,22,"Hand"
'
' The DATA list read from within the loop
Data "Wipe","Undo","Line","Free-","Square","Circle"
'
End Proc
'
Procedure WHICH_BUTTON
' Make the toolbox screen the one we are interested in
Screen 2
'
' Keep checking which zone the mouse is pointing at
' until mouse is clicked. MZ will then hold that zone's
' number (1 to 6). MK will tell which Mouse button was
' pressed Left = 1 Right = 2 Both = 3
'
' Repeat/Until loop. Loops until a condition is met.
Repeat
MZ=Mouse Zone
MK=Mouse Key
Until Mouse Click
'
' If you're in zone 1 and pressed the right button then bye!
If MZ=1 and MK=2 Then Stop
'
' If it's NOT Undo then copy all of drawing on to screen 0
If Not MZ=2 Then Screen Copy 1 To 0
'
' Make the drawing screen the current screen and....
Screen 1
' ....go and do whatever MZ was pointing at (1 to 6)
On MZ Proc WIPE,UNDO,STRAIGHT,F_HAND,SQUARE,CIRCUS
'
' Finished here so jump back to Main Loop.
End Proc
'
'
'
' These are the procedures that are called by selecting
' one of the buttons on screen
'
Procedure WIPE
' Clear the Screen
Cls
End Proc
'
Procedure UNDO
' Copy screen 0 back to screen 1
' You will not have copied the last drawing operation
' if you clicked on Undo (MZ=2)
Screen Copy 0 To 1
End Proc
'
' N.B. Circle, Line & Free etc. are words used by AMOS
' so they can not be used as procedure names.
'
Procedure STRAIGHT
' Call procedure to switch button on
SWITCHEROO
'
' Call procedure to find the start position
MOUSEY_MOUSEY
'
' Gr aphic Writing changes the way things are drawn
' on the screen. The number can range from 0 to 7.
'
' Change this to Gr Writing 1 and make nice patterns!
Gr Writing 2
'
' Keep switching between ink colours 0 & 1, drawing a line
' between start & current position until mouse is clicked.
'
' Do/Loop. Loops continuosly until exit condition is met.
Do
Ink 0
XPOSNOW=X Screen(X Mouse)
YPOSNOW=Y Screen(Y Mouse)
Draw XSTARTPOS,YSTARTPOS To XPOSNOW,YPOSNOW
Ink 1
Draw XSTARTPOS,YSTARTPOS To XPOSNOW,YPOSNOW
'
' Jump out of loop if mouse button pressed.
Exit If Mouse Click
'
Loop
'
' draw line in last position
Gr Writing 1
Draw XSTARTPOS,YSTARTPOS To XPOSNOW,YPOSNOW
'
' Switch button off
SWITCHEROO
End Proc
'
Procedure F_HAND
' Most of the drawing procedures are much alike
' so see the STRAIGHT procedure for details.
'
SWITCHEROO
MOUSEY_MOUSEY
'
' Keep drawing while a mouse key is pressed down
' Left button = 1 Right = 2 Both together = 3
'
' While/Wend loop. While a condition is true keep looping
While Not Mouse Key=0
XPOSNOW=X Screen(X Mouse)
YPOSNOW=Y Screen(Y Mouse)
Draw XSTARTPOS,YSTARTPOS To XPOSNOW,YPOSNOW
XSTARTPOS=XPOSNOW : YSTARTPOS=YPOSNOW
Wend
'
SWITCHEROO
End Proc
'
Procedure SQUARE
' Most of the drawing procedures are much alike
' so see the STRAIGHT procedure for details.
'
SWITCHEROO
MOUSEY_MOUSEY
Gr Writing 2
'
' create a box .........
Do
Ink 0
XPOSNOW=X Screen(X Mouse)
YPOSNOW=Y Screen(Y Mouse)
Box XSTARTPOS,YSTARTPOS To XPOSNOW,YPOSNOW
Ink 1
Box XSTARTPOS,YSTARTPOS To XPOSNOW,YPOSNOW
Exit If Mouse Click
Loop
'
Gr Writing 1
Box XSTARTPOS,YSTARTPOS To XPOSNOW,YPOSNOW
'
SWITCHEROO
End Proc
'
Procedure CIRCUS
' Most of the drawing procedures are much alike
' so see the STRAIGHT procedure for details.
'
SWITCHEROO
MOUSEY_MOUSEY
Gr Writing 2
'
' ...... and a circle/oval
Do
Ink 0
XPOSNOW=X Screen(X Mouse)
YPOSNOW=Y Screen(Y Mouse)
'
' Calculate the two radii
RADX=XPOSNOW-XSTARTPOS : RADY=YPOSNOW-YSTARTPOS
'
' Change any negative values to positive
' i.e. ABSolute value of -7 is 7
RADX = Abs(RADX) : RADY = Abs(RADY)
'
' and we dont want zero either!
If RADX=0 Then RADX=1
If RADY=0 Then RADY=1
'
Ellipse XSTARTPOS,YSTARTPOS,RADX,RADY
Ink 1
Ellipse XSTARTPOS,YSTARTPOS,RADX,RADY
Exit If Mouse Click
Loop
'
Gr Writing 1
Ellipse XSTARTPOS,YSTARTPOS,RADX,RADY
'
SWITCHEROO
End Proc
'
Procedure MOUSEY_MOUSEY
'
' Wait for a mouse click record x & y start positions.
' The Mouse uses Hardware Coordinates so convert
' these with the X/Y Screen function to find the
' position on the screen.
Repeat
XSTARTPOS=X Screen(X Mouse)
YSTARTPOS=Y Screen(Y Mouse)
Until Mouse Click
'
' Return to where you came from with the new XSTARTPOS & YSTARTPOS
End Proc
'
Procedure SWITCHEROO
' Switch the colours when selecting a button.
' Switch them back again when done.
Screen 2
Gr Writing 2
'
' Work out the top left corner of the button.
' * means multiply.
UPPERLEFT=((MZ-1)*53)
'
' and the bottom right one.
BOTTOMRIGHT=UPPERLEFT+53
'
' Draw a bar over button to reverse the colours
Bar UPPERLEFT,5 To BOTTOMRIGHT,25
'
Gr Writing 1
Screen 1
End Proc
'
'
' That's it for now!
' Next time more tools & colours & even much more betterer too!